<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('信用评分列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>地区：</label>
                                <select name="city" th:with="type=${@dict.getType('b_city')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>周期类型：</label>
                                <select name="periodType" th:with="type=${@dict.getType('b_period_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>考核周期：</label>
                                <input type="text" name="gradePeriod"/>
                            </li>
<!--                            <li>-->
<!--                                <label>状态：</label>-->
<!--                                <select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                                </select>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="addGrade()" shiro:hasPermission="system:grade:add">
                    <i class="fa fa-plus"></i> 添加
                </a>

                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:grade:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:grade:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:grade:remove')}]];
        var diagnoseFlag=[[${@permission.hasPermi('system:diagnose:list')}]];
        var cityDatas = [[${@dict.getType('b_city')}]];
        var periodTypeDatas = [[${@dict.getType('b_period_type')}]];
        var prefix = ctx + "system/grade";
        /*添加评分-*/
		function addGrade() {
		    var url = ctx + 'system/grade/add';
		    $.modal.openTab("添加评分", url);
		}
		/*显示已添加评分-*/
		function viewGrade(id) {
		    var url = ctx + 'system/grade/viewGrade/'+id;
		    $.modal.openTab("评分详情", url);
		}
		/*编辑已添加评分-*/
		function editGrade(id) {
		    var url = ctx + 'system/grade/editGrade/'+id;
		    $.modal.openTab("修改评分", url);
		}
        /*跳转到诊断书-*/
        function openDiagnose(id) {
            var url = ctx + 'system/grade/editDiagnose/'+id;
            $.modal.openTab("诊断书管理", url);
        }
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "信用评分",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '评分ID',
                    visible: false
                },
                {
                    field: 'gradeName',
                    title: '信用评分名称',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a href="javascript:void(0)" onclick="viewGrade(\'' + row.id + '\')">'+value+'</a> ');
                        return actions.join('');
                    }
                },
                {
                    field: 'city',
                    title: '地区',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(cityDatas, value);
                    }
                },
                {
                    field: 'periodType',
                    title: '周期类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(periodTypeDatas, value);
                    }
                },
                {
                    field: 'gradePeriod',
                    title: '考核周期'
                },
                {
                    field: 'maxScore',
                    title: '总分'
                },
                {
                    field: 'totalScore',
                    title: '预评分'
                },
                // {
                //     field: 'status',
                //     title: '状态',
		        // 	formatter: function (value, row, index) {
		        // 		return statusTools(row);
		        // 	}
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editGrade(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + diagnoseFlag + '" href="javascript:void(0)" onclick="openDiagnose(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>诊断书</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 用户状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}

		/* 用户管理-停用 */
		function disable(id) {
			$.modal.confirm("确认要停用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
		    })
		}

		/* 用户管理启用 */
		function enable(id) {
			$.modal.confirm("确认要启用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
		    })
		}
    </script>
</body>
</html>